package com.yuanqi.springboot_banksystem.controller;

import com.yuanqi.springboot_banksystem.entity.UserEntity;
import com.yuanqi.springboot_banksystem.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CommonController extends BaseController{

    @Autowired
    UserService userService;

    @GetMapping({"/","/login"})
    public String login(){
        return "loginPage";
    }

    @GetMapping("/invalid")
    public String invalid(){
        return "invalidPage";
    }

    @RequestMapping("/index")
    public String index(){
        return "indexPage";
    }

    @GetMapping("/register")
    public String register(){
        return "registerPage";
    }

    @GetMapping("/welcome")
    public String welcome(){
        return "welcomePage";
    }

    @GetMapping("/updatePassword")
    public String updatePassword(){
        return "updatePasswordPage";
    }
    @GetMapping("/updateTel")
    public String updateTel(){
        return "updateTelPage";
    }

    @GetMapping("/transfermoney")
    public String transfermoney(){
        return "transfermoneyPage";
    }

    @GetMapping("/cold")
    public String cold(Model model){
        String username = (String) SecurityUtils.getSubject().getPrincipal();

        UserEntity userEntity = userService.selectUser(username);

        if (userEntity.getIs_cold()==1){
            model.addAttribute("cold","true");
        }
        else {
            model.addAttribute("cold","false");
        }

        return "coldPage";
    }

    @GetMapping("/queryuser")
    public String queryuser(){
        return "queryuserPage";
    }

    @GetMapping("/updateuser")
    public String updateuser(){
        return "updateuserPage";
    }

    @GetMapping("/revoke")
    public String revoke(){
        return "revokePage";
    }

    @GetMapping("/addUser")
    public String addUser(){
        return "addUserPage";
    }

    @GetMapping("/deleteUser")
    public String deleteUser(){
        return "deleteUserPage";
    }
}
